package logic

import (
	"context"
	"src/models/mysql"
	"src/srcclient"

	"src/internal/svc"
	"src/src"

	"github.com/zeromicro/go-zero/core/logx"
)

type AccountListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAccountListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AccountListLogic {
	return &AccountListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AccountListLogic) AccountList(in *src.AccountListRequest) (*src.AccountListResponse, error) {
	// todo: add your logic here and delete this line
	var list []mysql.Account
	mysql.DB.Debug().Model(&list).Find(&list)

	var slice []*srcclient.AccountListStruct

	for _, good := range list {
		lists := srcclient.AccountListStruct{
			Tel:      good.Tel,
			Password: good.Password,
			Status:   good.Status,
			Account:  good.Account,
		}
		slice = append(slice, &lists)
	}

	return &src.AccountListResponse{Accountlist: slice}, nil
}
